<?php

namespace app\components\helpers;

/**
 * 下拉列表数据
 */
class DropListHelper
{
    public $list = [];

    public function format($arr, $parentId = 0, $level = 0)
    {
        foreach ($arr as $key => $value) {
            if ($value['parentId'] == $parentId) {
                $value['level'] = $level;
                $value['name'] = str_repeat('---', $level) . ' ' . $value['name'];
                $this->list[] = $value;
                unset($arr[$key]);
                $this->format($arr, $value['id'], $level + 1);
            }
        }
        return $this->list;
    }
}